package com.zpark.jsoup;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.File;
import java.io.IOException;
import java.net.URLDecoder;

/**
 * @PackageName: com.zpark.jsoup
 * @ClassName: JsoupPrintFormParameters
 * @Description:
 * @author: RZS
 * @date: 2021/8/16  10:03
 */
public class JsoupPrintFormParameters {
    public static void main(String[] args) throws IOException {
        // 获取html文件所在路径
        String path = JsoupPrintFormParameters.class.getClassLoader().getResource("static/register.html").getPath();
        // 由于路径包含中文，所以需要进行解码
        path = URLDecoder.decode(path, "utf-8");

        Document doc = Jsoup.parse(new File(path),"utf-8");
        Element loginform = doc.getElementById("registerform");

        Elements inputElements = loginform.getElementsByTag("input");
        for (Element inputElement : inputElements) {
            String key = inputElement.attr("name");
            String value = inputElement.attr("value");
            System.out.println("参数名: "+key+" 参数值: "+value);
        }
    }
}
